package model.map;

import java.util.HashMap;
import java.util.Map;

class HexTile implements GameTile
{
	private Map<Direction, HexTile > neighbors;
	private String terrainType;
	private Current current;
	private HexRelativityCoordinate internalCoordinate;
	private boolean mark;
	private int x;
	private int y;
	
	public HexTile(int x, int y, String terrain)
	{
		this.x = x;
		this.y = y;
		this.terrainType = terrain;
		internalCoordinate = new HexRelativityCoordinate();
		current = null;
		mark = false;
		neighbors = new HashMap<Direction, HexTile>();
	}
	
	public void addNeighbor(Direction d, HexTile t)
	{
		neighbors.put(d, t);
	}
	
	public void setCurrent(Current c)
	{
		current = c;
	}
	
	public GameTile getNeighborAt(Direction d)
	{
		return neighbors.get(d);
	}

	public Direction getCurrentDirection() 
	{
		if (hasCurrent())
			return current.getDirection();
		return Direction.C;
	}

	public int getCurrentSpeed() {
		if (hasCurrent())
			return current.getSpeed();
		return 0;
	}

	public int getRelativeX() {
		return internalCoordinate.getX();
	}

	public int getRelativeY() {
		return internalCoordinate.getY();
	}

	public int getRelativeZ() {
		return internalCoordinate.getZ();
	}
	
	public void setTerrainType(String terrainType) {
		this.terrainType = terrainType;
	}

	public String getTerrainType() {
		return terrainType;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public boolean hasCurrent() {
		return current != null;
	}
	
	public boolean isMarked()
	{
		return mark;
	}
	
	public void mark()
	{
		mark = true;
	}
	
	public void unmark()
	{
		mark = false;
	}
	
	public void setRelativeCoord(int x, int y, Direction d)
	{
		internalCoordinate = new HexRelativityCoordinate(x, y, d);
	}
	
	public String toString()
	{
		String result = "(" + getX() + ", " + getY() + "), " +
						"(" + getRelativeX() + ", " + getRelativeY() + ", " + getRelativeZ() + "): " + getTerrainType() + "\n";
		if (hasCurrent())
			result += "Current of strength " + getCurrentSpeed() + " going " + getCurrentDirection();
		else
			result += "No current";
		
		return result;
	}

	@Override
	public boolean hasNeighborAt(Direction dir) {
		return neighbors.containsKey(dir);
	}
	
	// TODO Fix RelativityDirections
}
